// LOAD DATA OF OPTIONS RETURNS FOR 1 YEAR AROUND BREXIT
use "Brexit_Data.dta", clear
tsset id month

// OPTION RETURNS AROUND BREXIT
	preserve
	drop if floor(month/100) == 201605 // This is because returns are for the next month, I remove the option returns in 06/2016
		regress call BRisk BRisk_Post Post  BSentiment  Size IdioVol Reversal Momentum Illiquidity BM GrossProfit Inst Leverage, vce(cluster id)
		reghdfe call BRisk BRisk_Post Post BSentiment Size  IdioVol Reversal Momentum Illiquidity BM GrossProfit Inst Leverage, a(month) vce(cluster id)
		reghdfe call BRisk BRisk_Post Post BSentiment Size IdioVol Reversal Momentum Illiquidity BM GrossProfit Inst Leverage, a(month Industry) vce(cluster id)
		reghdfe call BRisk BRisk_Post Post  BSentiment Size  Reversal Momentum Illiquidity BM GrossProfit Inst Leverage, a(month id) vce(cluster id)
	restore

	
// DYNAMIC FIGURE (APPENDIX)
	preserve
	    replace month = floor(month/100)
	    gen time = month
		replace time = -1 if inlist(time, 201604, 201603, 201602, 201601) 
		replace time = -2 if inlist(time, 201512, 201511, 201510, 201509)
		replace time = -3 if inlist(time, 201508, 201507, 201506, 201505)
        replace time = 0 if inlist(time, 201605) 
		replace time = 1 if inlist(time, 201606, 201607, 201608, 201609)
		replace time = 2 if inlist(time, 201610, 201611, 201612, 201701)
		replace time = 3 if inlist(time, 201702, 201703, 201704, 201705)

		gen before3 = (time==-3)*BRisk
		gen before2 = (time==-2)*BRisk
		gen before1 = (time==-1)*BRisk	
		gen after0 = (time==0)*BRisk
		gen after1 = (time==1)*BRisk
		gen after2 = (time==2)*BRisk
		gen after3 = (time==3)*BRisk
	
	*drop if time == 0
	reghdfe call before3 before2 before1 after1 after2 after3 BSentiment Size IdioVol Reversal Momentum Illiquidity BM GrossProfit Inst Leverage, a(month Industry) vce(cluster id)
	
	matrix T = r(table)
	g coef = 0 if time == -1
	g se = 0 if time == -1

	forvalues t = -3(1)3 {
	if `t' < -1 {
		local tname = abs(`t')
		replace coef = T[1,colnumb(T,"before`tname'")] - T[1,colnumb(T,"before1")] if time == `t'
		replace se = T[2,colnumb(T,"before`tname'")] if time == `t'
	}
	else if `t' >= 0 {
		replace coef =  T[1,colnumb(T,"after`t'")] - T[1,colnumb(T,"before1")] if time == `t'
		replace se = T[2,colnumb(T,"after`t'")] if time == `t'
	}
	}
	
	* Make confidence intervals
	g ci_top = coef+1.96*se
	g ci_bottom = coef - 1.96*se

	keep time coef se ci_*
	duplicates drop

	sort time
	keep if inrange(time, -3, 3)
	
	summ ci_top
	local top_range = r(max)
	summ ci_bottom
	local bottom_range = r(min)
	
	twoway (sc coef time) ///
	(rcap ci_top ci_bottom time)	///
	(function y = 0, range(-3 3)) ///
	(function y = 0, range(-1 0.5) horiz), ///
	xlabel(-3 "-12" -2 "-8" -1 "-4" 0 "Brexit" 1 "+4" 2 "+8" 3 "+12") ///
	xtitle("Months to Brexit") caption("95% Confidence Intervals Shown")
restore
